package com.example.distillapplication.ui.activity.base;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

import com.example.distillapplication.App;
import com.example.distillapplication.data.viewmodel.DataBaseViewModel;
import com.example.distillapplication.data.viewmodel.InstrumentStateViewModel;
import com.example.distillapplication.data.viewmodel.SerialMessageViewModel;
import com.example.distillapplication.data.viewmodel.SharedViewModel;

public class BaseActivity extends AppCompatActivity {
    protected SharedViewModel mSharedViewModel;
    protected DataBaseViewModel mDataBaseViewModel;
    protected InstrumentStateViewModel mInstrumentStateViewModel;
    protected SerialMessageViewModel mSerialMessageViewModel;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mSharedViewModel = getAppViewModelProvider().get(SharedViewModel.class);
        mDataBaseViewModel = getAppViewModelProvider().get(DataBaseViewModel.class);
        mInstrumentStateViewModel = getAppViewModelProvider().get(InstrumentStateViewModel.class);
        mSerialMessageViewModel = getAppViewModelProvider().get(SerialMessageViewModel.class);
    }

    public void showLongToast(String text) {
        Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show();
    }

    public void showShortToast(String text) {
        Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
    }

    protected ViewModelProvider getAppViewModelProvider() {
        return ((App) getApplicationContext()).getAppViewModelProvider(this);
    }

    protected ViewModelProvider getActivityViewModelProvider(AppCompatActivity activity) {
        return new ViewModelProvider(activity, activity.getDefaultViewModelProviderFactory());
    }

}
